/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdministrarParalelos.java
 *
 * Created on 20-ene-2013, 16:32:35
 */
package sisvoto.vista;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JList;
import sisvoto.DAO.ConsultasBD;
import sisvoto.ModeloDAO.AnioLectivoDAO;
import sisvoto.ModeloDAO.AnioParaleloDAO;
import sisvoto.ModeloDAO.ParaleloDAO;
import sisvoto.Utiles.Mensajes;
import sisvoto.modelo.AnioLectivo;
import sisvoto.modelo.Anio_Paralelo;
import sisvoto.modelo.Paralelo;
import sisvoto.modeloTablas.BotonCellEditor;
import sisvoto.modeloTablas.BotonCellRenderer;
import sisvoto.modeloTablas.ModelTableTipoAnio;

/**
 *
 * @author Dianita
 */
public class AdministrarParalelos extends javax.swing.JDialog {

    ArrayList<Anio_Paralelo> aniosp = new ArrayList<>();
    ModelTableTipoAnio modelotabla;
    List<AnioLectivo> anios = new ArrayList<>();
    List<Paralelo> paralelos = new ArrayList<>();
    AnioLectivo anio;
    Paralelo paralelo;

    /** Creates new form AdministrarParalelos */
    public AdministrarParalelos(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.anios = (ArrayList<AnioLectivo>) new ConsultasBD().buscarTodos("AnioLectivo");
        this.paralelos = (ArrayList<Paralelo>) new ConsultasBD().buscarTodos("Paralelo");
        this.anio = new AnioLectivo();
        this.paralelo = new Paralelo();
        initComponents();
        actualizarTabla();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        imagePanel1 = new com.mycsistemas.swingec.panel.ImagePanel();
        curvesPanel1 = new com.mycsistemas.swingec.panel.CurvesPanel();
        jLblAdmPrivilegio = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlparalelo = new javax.swing.JList();
        jLblBusPrivilegio = new javax.swing.JLabel();
        txtparalelo = new javax.swing.JTextField();
        btnEliminarN = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlanio = new javax.swing.JList();
        btnEditarN = new javax.swing.JButton();
        btnNuevoN = new javax.swing.JButton();
        btnGuardarN = new javax.swing.JButton();
        txtAnio = new javax.swing.JTextField();
        jLblBusPrivilegio1 = new javax.swing.JLabel();
        btnEliminarP = new javax.swing.JButton();
        btnEditarP = new javax.swing.JButton();
        btnNuevoP = new javax.swing.JButton();
        btnGuardarP = new javax.swing.JButton();
        jLblBusPrivilegio2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblaniosp = new javax.swing.JTable();
        jBtnAgregar = new javax.swing.JButton();
        jBtnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Administración de Años de Eduación");

        imagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/''_10102012_1738.jpeg"))); // NOI18N

        curvesPanel1.setLayout(null);

        jLblAdmPrivilegio.setFont(new java.awt.Font("Georgia", 3, 18));
        jLblAdmPrivilegio.setForeground(new java.awt.Color(255, 255, 255));
        jLblAdmPrivilegio.setText("Administración de Años de Educación ");
        curvesPanel1.add(jLblAdmPrivilegio);
        jLblAdmPrivilegio.setBounds(200, 40, 450, 21);

        jlparalelo.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${paralelos}");
        org.jdesktop.swingbinding.JListBinding jListBinding = org.jdesktop.swingbinding.SwingBindings.createJListBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jlparalelo);
        jListBinding.setDetailBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        bindingGroup.addBinding(jListBinding);

        jlparalelo.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlparaleloValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jlparalelo);

        curvesPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(240, 150, 140, 150);

        jLblBusPrivilegio.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblBusPrivilegio.setForeground(new java.awt.Color(255, 255, 255));
        jLblBusPrivilegio.setText("AÑOS DE EDUCACIÓN");
        curvesPanel1.add(jLblBusPrivilegio);
        jLblBusPrivilegio.setBounds(500, 70, 210, 30);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${paralelo.nombre}"), txtparalelo, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtparalelo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtparaleloKeyPressed(evt);
            }
        });
        curvesPanel1.add(txtparalelo);
        txtparalelo.setBounds(240, 110, 140, 30);

        btnEliminarN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/trash_32.png"))); // NOI18N
        btnEliminarN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarNActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnEliminarN);
        btnEliminarN.setBounds(160, 250, 40, 50);

        jlanio.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${anios}");
        jListBinding = org.jdesktop.swingbinding.SwingBindings.createJListBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jlanio);
        jListBinding.setDetailBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        bindingGroup.addBinding(jListBinding);

        jlanio.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlanioValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jlanio);

        curvesPanel1.add(jScrollPane2);
        jScrollPane2.setBounds(20, 150, 140, 150);

        btnEditarN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/Pencil3.png"))); // NOI18N
        btnEditarN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarNActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnEditarN);
        btnEditarN.setBounds(160, 200, 40, 50);

        btnNuevoN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/document_32.png"))); // NOI18N
        btnNuevoN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoNActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnNuevoN);
        btnNuevoN.setBounds(160, 150, 40, 50);

        btnGuardarN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/save_32.png"))); // NOI18N
        btnGuardarN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarNActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnGuardarN);
        btnGuardarN.setBounds(160, 110, 40, 30);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${anio.nombre}"), txtAnio, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtAnio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtAnioKeyPressed(evt);
            }
        });
        curvesPanel1.add(txtAnio);
        txtAnio.setBounds(20, 110, 140, 30);

        jLblBusPrivilegio1.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblBusPrivilegio1.setForeground(new java.awt.Color(255, 255, 255));
        jLblBusPrivilegio1.setText("NIVEL");
        curvesPanel1.add(jLblBusPrivilegio1);
        jLblBusPrivilegio1.setBounds(80, 80, 110, 30);

        btnEliminarP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/trash_32.png"))); // NOI18N
        btnEliminarP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarPActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnEliminarP);
        btnEliminarP.setBounds(380, 250, 40, 50);

        btnEditarP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/Pencil3.png"))); // NOI18N
        btnEditarP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarPActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnEditarP);
        btnEditarP.setBounds(380, 200, 40, 50);

        btnNuevoP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/document_32.png"))); // NOI18N
        btnNuevoP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoPActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnNuevoP);
        btnNuevoP.setBounds(380, 150, 40, 50);

        btnGuardarP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/save_32.png"))); // NOI18N
        btnGuardarP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarPActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnGuardarP);
        btnGuardarP.setBounds(380, 110, 40, 30);

        jLblBusPrivilegio2.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblBusPrivilegio2.setForeground(new java.awt.Color(255, 255, 255));
        jLblBusPrivilegio2.setText("PARALELO");
        curvesPanel1.add(jLblBusPrivilegio2);
        jLblBusPrivilegio2.setBounds(280, 80, 110, 30);

        tblaniosp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(tblaniosp);

        curvesPanel1.add(jScrollPane3);
        jScrollPane3.setBounds(460, 110, 290, 190);

        jBtnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/right_32.png"))); // NOI18N
        jBtnAgregar.setText("AGREGAR ");
        jBtnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnAgregarActionPerformed(evt);
            }
        });
        curvesPanel1.add(jBtnAgregar);
        jBtnAgregar.setBounds(460, 310, 140, 40);

        jBtnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/DeleteRed.png"))); // NOI18N
        jBtnCancelar.setText("Salir");
        jBtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnCancelarActionPerformed(evt);
            }
        });
        curvesPanel1.add(jBtnCancelar);
        jBtnCancelar.setBounds(610, 310, 140, 40);

        javax.swing.GroupLayout imagePanel1Layout = new javax.swing.GroupLayout(imagePanel1);
        imagePanel1.setLayout(imagePanel1Layout);
        imagePanel1Layout.setHorizontalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(curvesPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 831, Short.MAX_VALUE)
        );
        imagePanel1Layout.setVerticalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(curvesPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void txtparaleloKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtparaleloKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_txtparaleloKeyPressed

private void btnEliminarNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarNActionPerformed
// TODO add your handling code here:
    if (jlanio.getSelectedIndex() != -1) {
        if (new Mensajes().ConfirmacionDialogowarning(this, "¿Está seguro de Eliminar éste Registro?") == 0) {
            try {
                AnioLectivoDAO aDAO = new AnioLectivoDAO(anio);
                aDAO.update();
                aDAO.remove();
                new Mensajes().ConfirmacionDialogotick(this, "El Registro se ha Eliminado Con Éxito");
                this.bindingGroup.unbind();
                anios.remove(this.anio);
                jlanio.updateUI();
                txtAnio.setText("");
                this.bindingGroup.bind();
            } catch (Exception ex) {
                new Mensajes().StandarWarning(this, "                 No es Posible Eliminar. \n Éste Registro está Siendo Utilizado por el Sistema");
            }

        }
    } else {
        new Mensajes().StandarWarning(this, "Seleccione el registro que Desee Eliminar");
    }
}//GEN-LAST:event_btnEliminarNActionPerformed

private void btnEditarNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarNActionPerformed
// TODO add your handling code here:
    if (jlanio.getSelectedIndex() != -1) {
        txtAnio.setEnabled(true);
    } else {
        new Mensajes().StandarWarning(this, "Seleccione el registro que Desee Actualizar");
    }
}//GEN-LAST:event_btnEditarNActionPerformed

private void btnNuevoNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoNActionPerformed
// TODO add your handling code here:
    this.anio = new AnioLectivo();
    txtAnio.setEnabled(true);
    txtAnio.setText("");
}//GEN-LAST:event_btnNuevoNActionPerformed

private void btnGuardarNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarNActionPerformed
// TODO add your handling code here:
    if (txtAnio.getText().isEmpty()) {
        new Mensajes().StandarWarning(this, "Ingrese un Nivel de Educación");
    } else {
        AnioLectivoDAO adao = new AnioLectivoDAO(this.anio);
        if (this.anio.getId() == null) {
            if (existenuevoanio()) {
                try {
                    adao.persist();
                    bindingGroup.unbind();
                    anios = (ArrayList<AnioLectivo>) new ConsultasBD().buscarTodos("AnioLectivo");
                    bindingGroup.bind();
                    txtAnio.setText("");
                    anio = new AnioLectivo();
                    //new Mensajes().ConfirmacionDialogotick(this, "Agregado Exitosamente");
                } catch (Exception ex) {
                    new Mensajes().StandarWarning(this, "No se pudo agregar");
                }
            } else {
                new Mensajes().StandarWarning(this, "Ya Existe un Registro con esa Denominación ");
            }
        } else {
            if (existeactualizaranio()) {
                try {
                    adao.update();
                    bindingGroup.unbind();
                    anios = (ArrayList<AnioLectivo>) new ConsultasBD().buscarTodos("AnioLectivo");
                    txtAnio.setText("");
                    jlanio.updateUI();
                    bindingGroup.bind();
                    new Mensajes().ConfirmacionDialogotick(this, "Actualizado Exitosamente");
                } catch (Exception ex) {
                    new Mensajes().StandarWarning(this, "No se pudo Actualizar");
                }
            } else {
                new Mensajes().StandarWarning(this, "Ya existe un Registro Con esa Denominación");
            }

        }

    }

}//GEN-LAST:event_btnGuardarNActionPerformed

private void txtAnioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAnioKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_txtAnioKeyPressed

private void btnEliminarPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarPActionPerformed
// TODO add your handling code here:
    if (jlparalelo.getSelectedIndex() != -1) {
        if (new Mensajes().ConfirmacionDialogowarning(this, "¿Está seguro de Eliminar éste Registro?") == 0) {
            try {
                ParaleloDAO pDAO = new ParaleloDAO(paralelo);
                pDAO.update();
                pDAO.remove();
                new Mensajes().ConfirmacionDialogotick(this, "El Registro se ha Eliminado Con Éxito");
                this.bindingGroup.unbind();
                paralelos.remove(this.paralelo);
                jlparalelo.updateUI();
                txtparalelo.setText("");
                this.bindingGroup.bind();
            } catch (Exception ex) {
                new Mensajes().StandarWarning(this, "                 No es Posible Eliminar. \n Éste Registro está Siendo Utilizado por el Sistema");
            }
        }
    } else {
        new Mensajes().StandarWarning(this, "Seleccione el registro que Desee Eliminar");
    }
}//GEN-LAST:event_btnEliminarPActionPerformed

private void btnEditarPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarPActionPerformed
// TODO add your handling code here:
    if (jlparalelo.getSelectedIndex() != -1) {
        txtparalelo.setEnabled(true);
    } else {
        new Mensajes().StandarWarning(this, "Seleccione el registro que Desee Actualizar");
    }
}//GEN-LAST:event_btnEditarPActionPerformed

private void btnNuevoPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoPActionPerformed
// TODO add your handling code here:
    this.paralelo = new Paralelo();
    txtparalelo.setEnabled(true);
    txtparalelo.setText("");
}//GEN-LAST:event_btnNuevoPActionPerformed

private void btnGuardarPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarPActionPerformed
// TODO add your handling code here:
    if (txtparalelo.getText().isEmpty()) {
        new Mensajes().StandarWarning(this, "Ingrese un Paralelo");
    } else {
        ParaleloDAO pdao = new ParaleloDAO(this.paralelo);
        if (this.paralelo.getId() == null) {
            if (existenuevoparalelo()) {
                try {
                    pdao.persist();
                    bindingGroup.unbind();
                    paralelos = (ArrayList<Paralelo>) new ConsultasBD().buscarTodos("Paralelo");
                    bindingGroup.bind();
                    txtparalelo.setText("");
                    paralelo = new Paralelo();
                    //new Mensajes().ConfirmacionDialogotick(this, "Agregado Exitosamente");
                } catch (Exception ex) {
                    new Mensajes().StandarWarning(this, "No se pudo Agregar");
                }
            } else {
                new Mensajes().StandarWarning(this, "Ya Existe un Registro con esa Denominación ");
            }
        } else {
            if (existeactualizarparalelo()) {
                try {
                    pdao.update();
                    bindingGroup.unbind();
                    paralelos = (ArrayList<Paralelo>) new ConsultasBD().buscarTodos("Paralelo");
                    txtparalelo.setText("");
                    jlparalelo.updateUI();
                    bindingGroup.bind();
                    new Mensajes().ConfirmacionDialogotick(this, "Actualizado Exitosamente");
                } catch (Exception ex) {
                    new Mensajes().StandarWarning(this, "No se pudo Actualizar");
                }
            } else {
                new Mensajes().StandarWarning(this, "Ya existe un Registro Con esa Denominación");
            }

        }

    }
}//GEN-LAST:event_btnGuardarPActionPerformed

private void jBtnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnAgregarActionPerformed
// TODO add your handling code here:
    if (validarobjetos()) {
        if (existeanioparalelo(String.valueOf(anio.getId()), String.valueOf(paralelo.getId()))) {
            Anio_Paralelo ap = new Anio_Paralelo();
            ap.setParalelo(paralelo);
            ap.setAnio(anio);
            AnioParaleloDAO apdao = new AnioParaleloDAO(ap);
            try {
                apdao.persist();
                actualizarTabla();
            } catch (Exception ex) {
                new Mensajes().StandarWarning(this, "No se pudo Agregar");
            }
        } else {
            new Mensajes().StandarWarning(this, "            Ya Existe un Registro \n Con el Nivel y Paralelo Seleccionados");
        }
    } else {
        new Mensajes().ConfirmacionDialogowarning(this, "Seleccione un Nivel y un Paralelo antes de Agregar");
    }


}//GEN-LAST:event_jBtnAgregarActionPerformed

private void jBtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnCancelarActionPerformed
// TODO add your handling code here:
    dispose();
}//GEN-LAST:event_jBtnCancelarActionPerformed

private void jlanioValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlanioValueChanged
// TODO add your handling code here:
    if (jlanio.getSelectedIndex() != -1) {
        this.anio = ((ArrayList<AnioLectivo>) new ConsultasBD().buscarPOR("AnioLectivo", "nombre", "'" + jlanio.getSelectedValue() + "'")).get(0);
        txtAnio.setText(this.anio.getNombre());
        txtAnio.setEnabled(false);
    }
}//GEN-LAST:event_jlanioValueChanged

private void jlparaleloValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlparaleloValueChanged
// TODO add your handling code here:
    if (jlparalelo.getSelectedIndex() != -1) {
        this.paralelo = ((ArrayList<Paralelo>) new ConsultasBD().buscarPOR("Paralelo", "nombre", "'" + jlparalelo.getSelectedValue() + "'")).get(0);
        txtparalelo.setText(this.paralelo.getNombre());
        txtparalelo.setEnabled(false);
    }
}//GEN-LAST:event_jlparaleloValueChanged

    /**
     * @param args the command line arguments
     */

    public List<AnioLectivo> getAnios() {
        return anios;
    }

    public void setAnios(List<AnioLectivo> anios) {
        this.anios = anios;
    }

    public List<Paralelo> getParalelos() {
        return paralelos;
    }

    public void setParalelos(List<Paralelo> paralelos) {
        this.paralelos = paralelos;
    }

    public AnioLectivo getAnio() {
        return anio;
    }

    public void setAnio(AnioLectivo anio) {
        this.anio = anio;
    }

    public Paralelo getParalelo() {
        return paralelo;
    }

    public void setParalelo(Paralelo paralelo) {
        this.paralelo = paralelo;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEditarN;
    private javax.swing.JButton btnEditarP;
    private javax.swing.JButton btnEliminarN;
    private javax.swing.JButton btnEliminarP;
    private javax.swing.JButton btnGuardarN;
    private javax.swing.JButton btnGuardarP;
    private javax.swing.JButton btnNuevoN;
    private javax.swing.JButton btnNuevoP;
    private com.mycsistemas.swingec.panel.CurvesPanel curvesPanel1;
    private com.mycsistemas.swingec.panel.ImagePanel imagePanel1;
    private javax.swing.JButton jBtnAgregar;
    private javax.swing.JButton jBtnCancelar;
    private javax.swing.JLabel jLblAdmPrivilegio;
    private javax.swing.JLabel jLblBusPrivilegio;
    private javax.swing.JLabel jLblBusPrivilegio1;
    private javax.swing.JLabel jLblBusPrivilegio2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList jlanio;
    private javax.swing.JList jlparalelo;
    private javax.swing.JTable tblaniosp;
    private javax.swing.JTextField txtAnio;
    private javax.swing.JTextField txtparalelo;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void actualizarTabla() {
        this.aniosp = (ArrayList<Anio_Paralelo>) new ConsultasBD().buscarTodos("Anio_Paralelo");
        modelotabla = new ModelTableTipoAnio(aniosp);
        tblaniosp.setModel(modelotabla);
        tblaniosp.setDefaultRenderer(JButton.class, new BotonCellRenderer());
        tblaniosp.setDefaultEditor(JButton.class, new BotonCellEditor("Anio_Paralelo", this.aniosp, modelotabla, tblaniosp,"ANIOPARALELO"));
        
        modelotabla.tamanioColumnas(tblaniosp);
        modelotabla.tamanioFilas(tblaniosp);
        tblaniosp.updateUI();
    }

    private boolean existenuevoanio() {
        ArrayList<AnioLectivo> as = (ArrayList<AnioLectivo>) new ConsultasBD().buscarPOR("AnioLectivo", "nombre", "'" + txtAnio.getText() + "'");
        if (as.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    private boolean existeactualizaranio() {
        //retorna true si el usuario ya existe
        ArrayList<AnioLectivo> usuars = (ArrayList<AnioLectivo>) new ConsultasBD().buscarExcepto("AnioLectivo", "id", String.valueOf(this.anio.getId()), "nombre", "'" + anio.getNombre() + "'");
        if (usuars.isEmpty()) {
            return true;
        }
        return false;
    }

    private boolean existenuevoparalelo() {
        ArrayList<Paralelo> ap = (ArrayList<Paralelo>) new ConsultasBD().buscarPOR("Paralelo", "nombre", "'" + txtparalelo.getText() + "'");
        if (ap.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    private boolean existeactualizarparalelo() {
        //retorna true si el usuario ya existe
        ArrayList<Paralelo> pars = (ArrayList<Paralelo>) new ConsultasBD().buscarExcepto("Paralelo", "id", String.valueOf(this.paralelo.getId()), "nombre", "'" + paralelo.getNombre() + "'");
        if (pars.isEmpty()) {
            return true;
        }
        return false;
    }

    private boolean validarobjetos() {
        if (anio.getId() != null && paralelo.getId() != null) {
            return true;
        }
        return false;
    }

    private boolean existeanioparalelo(String anio, String paralelo) {
        ArrayList<Anio_Paralelo> aps = (ArrayList<Anio_Paralelo>) new ConsultasBD().buscarPOR2("Anio_Paralelo", "anio", "'" + anio + "'", "paralelo", "'" + paralelo + "'");
        if (aps.isEmpty()) {
            return true;
        }
        return false;
    }
}
